package flc.ast.utils;

import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.TimeUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import flc.ast.bean.MyImgBean;
import flc.ast.bean.MyImgItemBean;

public class MhzDateUtils {

    //将图片和视频按日期整理分组
    public static List<MyImgBean> getDayData(List<String> listData) {
        List<MyImgBean> listDay = new ArrayList<>();
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd EE");//统一日期格式
        //使用 Map 来按照日期将 Event 分别存储到对应日期的 List 中
        Map<String, List<MyImgItemBean>> eventMap = new HashMap<>();
        for (String path : listData) {
            String date = TimeUtils.millis2String(FileUtils.getFileLastModified(path), format);
            if (!eventMap.containsKey(date)) {
                eventMap.put(date, new ArrayList<>());
            }
            eventMap.get(date).add(new MyImgItemBean(path, false));
        }
        //打印每个日期对应的 Event 列表
        for (Map.Entry<String, List<MyImgItemBean>> entry : eventMap.entrySet()) {
            listDay.add(new MyImgBean(entry.getKey(), entry.getValue(), false));//添加到总的集合
        }
        //降序排序
        Collections.sort(listDay, new Comparator<MyImgBean>() {
            @Override
            public int compare(MyImgBean e1, MyImgBean e2) {
                return e2.getDate().compareTo(e1.getDate());
            }
        });
        return listDay;
    }
}
